//
//  BCGotCommitCell.m
//  BangcaiDriver
//
//  Created by apple on 16/9/21.
//  Copyright © 2016年 BC. All rights reserved.
//

#import "BCGotCommitCell.h"

@interface BCGotCommitCell ()
{
    UIImageView *corner;
    UIImageView *diImg;
    UIImageView *position;
    UILabel *titleLab;
    UILabel *distLab;
    UILabel *titleLine;
    UILabel *prcice;
    UILabel *letterLab;

}

@end
    

@implementation BCGotCommitCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}


- (void)createView
{
    self.timeLab = [[UILabel alloc] init];
    self.topLine = [[UILabel alloc] init];
    self.bottomLine = [[UILabel alloc] init];
    self.bodyView = [[UIView alloc] init];


    corner = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"三角"]];
    diImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"di"]];
    position = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"定位"]];
    titleLab = [[UILabel alloc] init];
    prcice = [[UILabel alloc] init];
    prcice.textColor = BangcaiOrange;
    prcice.font = [UIFont systemFontOfSize:15];
    prcice.text = @"¥70.5";
    
    titleLab.font = [UIFont systemFontOfSize:14];
    titleLab.text = @"6个地点";
    titleLab.textColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    distLab = [[UILabel alloc] init];
    distLab.font = [UIFont systemFontOfSize:13];
    distLab.textColor = [UIColor whiteColor];
    distLab.text = @"25km";
    distLab.backgroundColor = BangcaiOrange;
    distLab.layer.cornerRadius = 3;
    distLab.layer.masksToBounds = YES;
    self.bodyView.backgroundColor = [UIColor colorWithRed:0.965 green:0.965 blue:0.965 alpha:1];
    titleLine = [[UILabel alloc] init];
    titleLine.backgroundColor = [UIColor colorWithRed:0.823 green:0.824 blue:0.823 alpha:1];
    letterLab = [[UILabel alloc] init];
    letterLab.font = [UIFont systemFontOfSize:14];
    letterLab.numberOfLines = 0;
    letterLab.textColor =[UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1];
    [self.bodyView addSubview:position];
    [self.bodyView addSubview:titleLab];
    [self.bodyView addSubview:distLab];
    [self.bodyView addSubview:titleLine];
    [self.bodyView addSubview:letterLab];
    [self.bodyView addSubview:prcice];
    
    
    self.bodyView.layer.cornerRadius = 2;
    self.bodyView.layer.borderColor = BangcaiOrange.CGColor;
    self.bodyView.layer.borderWidth = 1;
    self.timeLab.backgroundColor = [UIColor colorWithRed:0.999 green:0.689 blue:0.390 alpha:1];
    self.timeLab.layer.cornerRadius = 14;
    self.timeLab.layer.borderColor = [UIColor colorWithRed:1 green:0.527 blue:0 alpha:1].CGColor;
    self.timeLab.layer.borderWidth = 2;
    self.timeLab.layer.masksToBounds = YES;
    self.timeLab.textColor = [UIColor whiteColor];
    self.timeLab.font = [UIFont systemFontOfSize:12];
    self.timeLab.textAlignment = NSTextAlignmentCenter;
    self.topLine.backgroundColor = [UIColor colorWithRed:0.921 green:0.922 blue:0.921 alpha:1];
    self.bottomLine.backgroundColor = [UIColor colorWithRed:0.921 green:0.922 blue:0.921 alpha:1];
    
    [self.contentView addSubview:self.timeLab];
    [self.contentView addSubview:self.topLine];
    [self.contentView addSubview:self.bottomLine];
    [self.contentView addSubview:self.bodyView];
    [self.contentView addSubview:corner];
    [self.contentView addSubview:diImg];
    
   
}

- (void)layoutSubviews{
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.height.mas_equalTo(28);
        make.width.mas_equalTo(70);
        make.top.mas_equalTo(30);
    }];
    
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.timeLab.mas_centerX);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.timeLab.mas_top).with.offset(-8);
        make.width.mas_equalTo(1);
        
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.timeLab.mas_centerX);
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.timeLab.mas_bottom).with.offset(8);
        make.width.mas_equalTo(1);
    }];
    
    [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12);
        make.bottom.mas_equalTo(-4);
        make.left.mas_equalTo(self.timeLab.mas_right).with.offset(18);
        make.right.mas_equalTo(-12);
    }];
    
    [corner mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeLab.mas_centerY);
        make.right.mas_equalTo(self.bodyView.mas_left).with.offset(2);
        make.width.mas_equalTo(9);
        make.height.mas_equalTo(12);
    }];
    
    [diImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.bodyView.mas_bottom);
        make.width.equalTo(self.bodyView);
        make.left.equalTo(self.bodyView);
    }];
    
    [position mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(25);
        
    }];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.left.mas_equalTo(position.mas_right).with.offset(6);
    }];
    
    [distLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.left.mas_equalTo(titleLab.mas_right).with.offset(12);
        
    }];
    
    [titleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(corner.mas_bottom);
        make.left.mas_equalTo(position.mas_left);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        
    }];
    
    [letterLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(titleLine);
        make.top.mas_equalTo(titleLine.mas_bottom);
        make.bottom.mas_equalTo(-8);
        
    }];
    
    [prcice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(position);
        make.right.mas_equalTo(-12);
        
    }];
}

- (void)setLetter:(NSString *)letter{
    letterLab.text = letter;
}

@end
